# class DoFile():
#     def readTxt(self,fname):
#         try:
#             mF=rf"D:\python项目\datas\{fname}.txt"
#             with open(mF,mode='r',encoding='utf-8') as f:
#                 r= f.read()
#                 print(r)
#                 return r
#         except Exception as e:
#             print(f"发生了异常异常的信息是{e}")
#         else:
#             print("处理结束，不知道有没有发生异常")
#
#     def writeTxt(self,fname,txt):
#         try:
#             mF=rf"D:\python项目\datas\{fname}.txt"
#             with open(mF, mode='w', encoding='utf-8') as f:
#                 ad=f.write(f"{txt}")
#             with open(mF, mode='r', encoding='utf-8') as a:
#                 r = a.read()
#                 print(r)
#         except Exception as e:
#             print(f"发生了异常异常的信息是{e}")
#         else:
#             print("处理结束，不知道有没有发生异常")
# if __name__ == '__main__':
#     class1=DoFile()
#     class2 = DoFile()
#     class1.writeTxt("c1","高三一班,30,理科班,[40,90,100,70,69,77]")
#     class2.writeTxt("c2", "高三二班,31,理科班,[40,90,100,70,69,77]")
import os.path
import openpyxl
from openpyxl.workbook import Workbook
from openpyxl.worksheet.worksheet import Worksheet

from config.conf import pro_path, data_path
from log.doLog import DoLog
doLog = DoLog()
myLog = doLog.getLogger(__name__)
class DoFile():
    def readExcel(self,fname):
        try:
            mF = os.path.join(data_path, fname)
            wk:Workbook=openpyxl.load_workbook(mF,read_only=True)
            c:Worksheet=wk["sheet1"]
            print(c.values)
        except Exception as e:
            print(f"发生了异常异常的信息是{e}")
            myLog.error(f"文件异常: {e}")
        else:
            print("处理结束")
            myLog.info("处理结束")
    def readExcelByRowCol(self,fname,wtest,maxr,minr,maxc,minc):
        try:
            mF = os.path.join(data_path, fname)
            wk: Workbook = openpyxl.load_workbook(mF, read_only=True)
            c: Worksheet = wk[wtest]
            print(c.values)
        except Exception as e:
            print(f"文件异常:{e}")
            myLog.error(f"异常: {e}")
        else:
            print("处理结束")
            l = [i for i in c.iter_rows(maxr, minr, maxc, minc, values_only=True)]
            myLog.info("处理结束")
            return l




    def writeExcel(self, fname):
        wk = openpyxl.Workbook()
        st: Worksheet = wk.create_sheet("sheet1")
        st.cell(1, 1, "mes1")
        st.cell(1, 2, "mes2")
        st.cell(2, 1, "你好")
        st.cell(2, 2, "helloword")
        mF=rf"D:\python2504\datas\{fname}"
        wk.save(mF)

